﻿using System.Collections.Generic;
using AutoMapper;
using FikriKibar.Common.Validation.Abstract;
using FikriKibar.Common.Validation.Entities;
using FluentValidation.Results;

namespace FikriKibar.Common.Validation.FluentValidation
{
    public abstract class FluentBaseValidator : IFikriKibarValidator
    {
        public abstract bool IsValid { get; set; }
        protected readonly List<FikriKibarValidationResult> ValidationResults;

        protected FluentBaseValidator()
        {
            Mapper.CreateMap<ValidationFailure, FikriKibarValidationResult>().ForMember(dest => dest.AttemptedValue, opt => opt.MapFrom(src => src.AttemptedValue));
            Mapper.CreateMap<ValidationFailure, FikriKibarValidationResult>().ForMember(dest => dest.CustomState, opt => opt.MapFrom(src => src.CustomState));
            Mapper.CreateMap<ValidationFailure, FikriKibarValidationResult>().ForMember(dest => dest.ErrorMessage, opt => opt.MapFrom(src => src.ErrorMessage));
            Mapper.CreateMap<ValidationFailure, FikriKibarValidationResult>().ForMember(dest => dest.PropertyName, opt => opt.MapFrom(src => src.PropertyName));
            ValidationResults = new List<FikriKibarValidationResult>();

        }
        public abstract List<FikriKibarValidationResult> Validate();
    }
}
